package zjitc.servlet;

import zjitc.domain.User;
import zjitc.service.UserService;
import zjitc.service.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("utf-8");
        //获取数据
        String id = request.getParameter("id");
        System.out.println(id+"dsfhauifbaruibvibviabvib");
        //调用service方法
        UserService service = new UserServiceImpl();
        User user = service.findUserById(Integer.parseInt(id));
        //把user数据存入request域
        request.setAttribute("user",user);
        //用request进行跳转页面
        request.getRequestDispatcher("update.jsp").forward(request,response);

    }
}
